package usb;
import java.util.Scanner;
public class Test04 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入y游戏开始");
        String str = sc.next();
        while (str.equals("y")){
            int random=(int)(Math.random() * 100);
//            System.out.println(random);
            int num =0;
            int i=0;
            System.out.println("游戏开始");
            for(i=3;i>=0;i--){
                System.out.println("请输入数字");
                num = sc.nextInt();
                if (num>random) {
                    if (i==0){
                        System.out.println("游戏结束，你输了");
                        break;
                    }else {
                        System.out.println("猜大了");
                        System.out.println("还有"+i+"次机会");
                    }
                }else if (num<random){
                    if (i==0){
                        System.out.println("游戏结束，你输了");
                        break;
                    }else {
                        System.out.println("猜小了");
                        System.out.println("还有"+i+"次机会");
                    }
                }else {
                    System.out.println("猜对了，你赢了");
                    break;
                }
            }
            System.out.println("输入y继续游戏");
            str = sc.next();
            if(!str.equals("y")){
                break;
            }
        }
        System.out.println("游戏结束");

    }
}
